

// 滚动事件
document.addEventListener("scroll",function(){
    
    let rightImg = document.querySelector(".infor_top_right_img");
    let text01 =document.querySelector(".infor_top_right_text_01");
    let text02 =document.querySelector(".infor_top_right_text_02");
    let text03 =document.querySelector(".infor_top_right_text_03");
    let text04 =document.querySelector(".infor_top_right_text_04");
    let number01=document.querySelector(".infor_top_right_name_01");
    let number02=document.querySelector(".infor_top_right_name_02");
    let number03=document.querySelector(".infor_top_right_name_03");
    let number04=document.querySelector(".infor_top_right_name_04");
    let inforTopLeft=document.querySelector(".infor_top_left_001")
    let inforBotLeft=document.querySelector(".infor_bottom_left_001")
    let inforBotRight=document.querySelector(".infor_bottom_right_001")

    var t = document.documentElement.scrollTop||document.body.scrollTop

    if(t>10){
        rightImg.style.left="0px";
        text01.style.left="20px";
        text02.style.left="240px";
        inforTopLeft.style.left="0px"
    }
    if(t>140){
        number01.style.left="140px";
        number02.style.left="222px";
    }
    if(t>213){
        number03.style.left="140px";
        number04.style.left="222px";
    }
    if(t>330){
        text03.style.left="20px";
        text04.style.left="240px";
    }
    if(t>375){
        inforBotLeft.style.left="0px"
    }
    if(t>460){
        inforBotRight.style.left="0px"
    }
});

// 切换验证码
function createZero(n){
    if(typeof n === "string"){
        if(n.length < 2){
            return "0" + n
        }
        return n;
    }else{
        if(n<10){
            return "0"+n;
        }
        return n;
    }
};

function randomColor(){
    var r = random(0,255).toString(16);
    var g = random(0,255).toString(16);
    var b = random(0,255).toString(16);
    return "#" + createZero(r) + createZero(g) + createZero(b);
};


function random(min,max){
    if(min > max){
        var ls= min;
        min = max;
        max = ls;
    }
    return Math.floor(Math.random()*(max-min+1)+min);
};
// 验证码
    // 先生成一个随机库，内包含的每种类型的数量都是一致的，保证公平性
    // 数字*4
    // 小写字母*4
    // 大写字母*4
    // 12个   
function colorCode() {
    var str = "";
    for (var i = 0; i < 4; i++) {
        var num = random(0, 9);
        var az = String.fromCharCode(random(97, 122));
        var AZ = String.fromCharCode(random(65, 90));
        str = str + num + az + AZ;
    };

    // 从12个库中，再随机取4个，全部随机小写，随机同一个字符，也是随机
    var randomStr = "";
    for (var i = 0; i < 4; i++){
        var index = random(0, str.length - 1)
        randomStr += str[index];
    };
    yzimg.innerHTML =randomStr
    yzimg.style.color=randomColor()
    
};

var yztxt =document.querySelector(".yanzheng")
var yzimg =document.querySelector(".yanzheng_img")
window.onload=function(){
    colorCode()
};

yztxt.addEventListener("click",function(){
    colorCode()
},false);
yzimg.addEventListener("click",function(){
    colorCode()
},false);


// 获取焦点时边框变色
var companyName=document.querySelector(".company_name");
var useName = document.querySelector(".use_name");
var telName = document.querySelector(".tel_name");
var shopName = document.querySelector(".shop_name")
var textarea = document.querySelector("textarea")
shopName.onfocus=function(){
    shopName.style.borderColor='rgb(151, 229, 255)'
    shopName.style.borderWidth='2PX'
}
shopName.onblur=function(){
    shopName.style.borderColor='#dadada'
    shopName.style.borderWidth='1PX'
}
companyName.onfocus=function(){
    companyName.style.borderColor='rgb(151, 229, 255)'
    companyName.style.borderWidth='2PX'
}
companyName.onblur=function(){
    companyName.style.borderColor='#dadada'
    companyName.style.borderWidth='1PX'
}
useName.onfocus=function(){
    useName.style.borderColor='rgb(151, 229, 255)'
    useName.style.borderWidth='2PX'
}
useName.onblur=function(){
    useName.style.borderColor='#dadada'
    useName.style.borderWidth='1PX'
}
telName.onfocus=function(){
    telName.style.borderColor='rgb(151, 229, 255)'
    telName.style.borderWidth='2PX'
}
telName.onblur=function(){
    telName.style.borderColor='#dadada'
    telName.style.borderWidth='1PX'
}


// 验证
var pushCha =document.querySelector(".push_cha")
var push =document.querySelector(".push")
var btn=document.querySelector(".infor_left_btn")
var tishi1 =document.querySelector(".tishi1")
var tishi2 =document.querySelector(".tishi2")
var tishi3 =document.querySelector(".tishi3")
var tishi4 =document.querySelector(".tishi4")
var yz=document.querySelector(".infor_left_yan")
btn.addEventListener("click",function(){
    var str = shopName.value.replace(/(^\s*)|(\s*$)/g, '');
    var str1= yz.value.replace(/(^\s*)|(\s*$)/g, '');
    if(str==''){
        tishi1.style.display="block";
    }else if(str1==""){
        tishi2.style.display="block";
        tishi1.style.display="none";
    }else if(!(yz.value==yzimg.innerHTML)){
        tishi2.style.display="none";
        tishi1.style.display="none";
        tishi4.style.display="block";
        setTimeout(function(){
            tishi3.style.display="block";
            tishi4.style.display="none";
        },200)
    }else{
        push1()
    }
})
function push1(){
    tishi2.style.display="none";
    tishi1.style.display="none";
    tishi4.style.display="block";
    tishi3.style.display="none";
    push.style.display = "block";
    setTimeout(function(){
        tishi4.style.display="none";
    },1000)
    setTimeout(function(){
        location.reload()
        push.style.display = "none";
    },3000)
    pushCha.onclick=function(){
        push.style.display = "none";
    }
}

// 发送数据到后台
   
function ress(){
    ajax({
        type:"get",
        url:"../php/shop.php",
        data:{
            shopName:shopName.value,
            companyName:companyName.value,
            useName:useName.value,
            telName:telName.value,
            textarea:textarea.value,

        },
        success:function(res){
                 console.log(res)                  
        },
      
    })
} 

